package com.wealth.scsj.p_app.model;


import com.wealth.scsj.p_app.base.QueryCardBase;
import com.wealth.scsj.p_app.bean.QueryCardBean;

import dkmvp.net.ResponseCallback;
import dkmvp.net.ResponseHandler;
import dkmvp.net.RetryWithDelay;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 银行卡校验Model
 */

public class QueryCardModel extends BaseModel implements QueryCardBase.IModel {

    @Override
    public Subscription getData(String cardNum, final ResponseCallback<QueryCardBean> callback) {
        Observable<QueryCardBean> observable = service.QueryCard(cardNum,true);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<QueryCardBean>() {
                    @Override
                    public void call(QueryCardBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return sub;
    }


}
